package com.zhuchaooasystem.ui.home.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.adapter.holder.OrderTrackHolder;
import com.zhuchaooasystem.base.BaseActivity;
import com.zhuchaooasystem.common.Key;
import com.zhuchaooasystem.entity.OrderTrackEntity;
import com.zhuchaooasystem.presenter.home.ordertrack.OrderTrackContract;
import com.zhuchaooasystem.presenter.home.ordertrack.OrderTrackPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderTrackActivity extends BaseActivity<OrderTrackPresenter>
        implements OrderTrackContract.View {

    @BindView(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @BindView(R.id.actionbar_txt_title)
    TextView actionbarTxtTitle;
    @BindView(R.id.order_track_id)
    TextView orderTrackId;
    @BindView(R.id.order_track_state)
    TextView orderTrackState;
    @BindView(R.id.act_order_track_recyclerView)
    EasyRecyclerView recyclerView;

    @BindView(R.id.act_order_track_layout)
    LinearLayout layout;


    private String orderId = "";

    private RecyclerArrayAdapter adapter;

    private int size;//用来判断数据是不是大于一个

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_track);
        ButterKnife.bind(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_order_track;
    }

    @Override
    protected OrderTrackPresenter getPresenter() {
        return new OrderTrackPresenter(mContext, this);
    }

    @Override
    protected void initVariables() {
        orderId = getIntent().getStringExtra(Key.ORIDERID);

    }

    @Override
    protected void initView() {

        actionbarIvBack.setVisibility(View.VISIBLE);
        actionbarTxtTitle.setText("订单跟踪");

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));


        mPresenter.downOrderTrack(orderId);
//        mPresenter.downOrderTrack("12729");
    }

    @Override
    protected void initDataAndLoadData() {

    }

    @OnClick(R.id.actionbar_iv_back)
    public void onClick(View view) {
        switch (view.getId()) {
            //返回
            case R.id.actionbar_iv_back:
                OrderTrackActivity.this.finish();
                break;
        }
    }

    @Override
    public void showOrderTrack(OrderTrackEntity entity) {

        layout.setVisibility(View.VISIBLE);

        orderTrackId.setText("订单编号：" + entity.getOrdercode());
        orderTrackState.setText("订单状态：" + entity.getOrderStatus());

        size = entity.getListNotes().size();

        recyclerView.setAdapter(adapter = new RecyclerArrayAdapter(mContext) {
                    @Override
                    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

                        return new OrderTrackHolder(parent, size);
                    }
                }
        );

        adapter.addAll(entity.getListNotes());
    }
}
